package archer.application.core.api.internal.system;

import archer.application.core.api.BaseController;
import archer.application.core.entity.user.Staff;
import archer.application.core.service.system.StaffService;
import archer.application.core.service.user.UserService;
import archer.framework.protocol.result.ExecuteResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author christ
 * @date 2016/6/7
 */
@RestController
@RequestMapping("/api/v*/internal/system/staff")
public class StaffApi extends BaseController {

    @Autowired
    StaffService staffService;

    @Autowired
    UserService userService;

    @RequestMapping("login")
    public ExecuteResult login(String loginName, String password) {

        return staffService.login(loginName, password);
    }

    @RequestMapping("logout")
    public ExecuteResult logout() {

        return staffService.logout();
    }

    @RequestMapping("store")
    public ExecuteResult store(Staff staff) {

        return staffService.store(staff);
    }

    @RequestMapping("delete")
    public ExecuteResult delete(String id) {

        return staffService.delete(id);
    }

    @RequestMapping("deleteAll")
    public ExecuteResult deleteAll(String ids) {

        return staffService.deleteAll(split(ids));
    }

    @RequestMapping("findPagedList")
    public ExecuteResult findPageList(String queryCondition) {

        return staffService.findPagedList(asCondition(queryCondition));
    }

    /**
     * 获得某个用户的所有菜单数据（包含不显示的）
     *
     * @return
     */
    @RequestMapping("findMenuList")
    public ExecuteResult findMenuList(String id) {

        return staffService.findMenuList(id);
    }

    /**
     * 获得当前登录用户的所有菜单数据（包含不显示的）
     *
     * @return
     */
    @RequestMapping("findMyMenuList")
    public ExecuteResult findMyMenuList() {

        return staffService.findMenuList(getCurrentUserId());
    }

    /**
     * 查询当前登录用户的显示菜单
     *
     * @return
     */
    @RequestMapping(value = "findMyDisplayMenuList")
    public ExecuteResult findMyDisplayMenuList() {

        return staffService.findMyDisplayMenuList(getCurrentUserId());
    }

    /**
     * 查询某个用户的角色列表
     *
     * @param id
     * @return
     */
    @RequestMapping("findRoleList")
    public ExecuteResult findRoleList(String id) {

        return staffService.findRoleList(id);
    }

    /**
     * 查询当前登录用户的角色列表
     *
     * @return
     */
    @RequestMapping("findMyRoleList")
    public ExecuteResult findMyRoleList() {

        return staffService.findRoleList(getCurrentUserId());
    }

    /**
     * 修改密码
     *
     * @param id
     * @param oldPassword
     * @param newPassword
     * @return
     */
    @RequestMapping("changePassword")
    public ExecuteResult changePassword(String id, String oldPassword, String newPassword) {

        return userService.changePassword(id, oldPassword, newPassword);
    }

}
